package org.jeecg.modules.rental.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.rental.entity.IotTerminalTemp;
import org.jeecg.modules.rental.mapper.IotTerminalTempMapper;
import org.jeecg.modules.rental.service.IIotTerminalTempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 终端上线临时
 * @Author: jeecg-boot
 * @Date:   2024-12-24
 * @Version: V1.0
 */
@Api(tags="终端上线临时")
@RestController
@RequestMapping("/rental/iotTerminalTemp")
@Slf4j
public class IotTerminalTempController extends JeecgController<IotTerminalTemp, IIotTerminalTempService> {
	@Autowired
	private IIotTerminalTempService iotTerminalTempService;
	@Autowired
	private IotTerminalTempMapper iotTerminalTempMapper;
	
	/**
	 * 分页列表查询
	 *
	 * @param iotTerminalTemp
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "终端上线临时-分页列表查询")
	@ApiOperation(value="终端上线临时-分页列表查询", notes="终端上线临时-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<IotTerminalTemp>> queryPageList(IotTerminalTemp iotTerminalTemp,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<IotTerminalTemp> queryWrapper = QueryGenerator.initQueryWrapper(iotTerminalTemp, req.getParameterMap());
		Page<IotTerminalTemp> page = new Page<IotTerminalTemp>(pageNo, pageSize);
		IPage<IotTerminalTemp> pageList = iotTerminalTempService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param iotTerminalTemp
	 * @return
	 */
	@AutoLog(value = "终端上线临时-添加")
	@ApiOperation(value="终端上线临时-添加", notes="终端上线临时-添加")
	//@RequiresPermissions("org.jeecg.modules.demo:iot_terminal_temp:add")
	@PostMapping(value = "/syncIot")
	public Result<String> syncIot(@RequestBody IotTerminalTemp iotTerminalTemp) {

		return iotTerminalTempService.syncIot(iotTerminalTemp);
	}



	@AutoLog(value = "终端上线临时-添加")
	@ApiOperation(value="终端上线临时-添加", notes="终端上线临时-添加")
	//@RequiresPermissions("org.jeecg.modules.demo:iot_terminal_temp:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody IotTerminalTemp iotTerminalTemp) {
		iotTerminalTempService.save(iotTerminalTemp);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param iotTerminalTemp
	 * @return
	 */
	@AutoLog(value = "终端上线临时-编辑")
	@ApiOperation(value="终端上线临时-编辑", notes="终端上线临时-编辑")
	//@RequiresPermissions("org.jeecg.modules.demo:iot_terminal_temp:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody IotTerminalTemp iotTerminalTemp) {
		iotTerminalTempService.updateById(iotTerminalTemp);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "终端上线临时-通过id删除")
	@ApiOperation(value="终端上线临时-通过id删除", notes="终端上线临时-通过id删除")
	//@RequiresPermissions("org.jeecg.modules.demo:iot_terminal_temp:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		iotTerminalTempService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "终端上线临时-批量删除")
	@ApiOperation(value="终端上线临时-批量删除", notes="终端上线临时-批量删除")
	//@RequiresPermissions("org.jeecg.modules.demo:iot_terminal_temp:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.iotTerminalTempService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "终端上线临时-通过id查询")
	@ApiOperation(value="终端上线临时-通过id查询", notes="终端上线临时-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<IotTerminalTemp> queryById(@RequestParam(name="id",required=true) String id) {
		IotTerminalTemp iotTerminalTemp = iotTerminalTempService.getById(id);
		if(iotTerminalTemp==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(iotTerminalTemp);
	}


	 @ApiOperation(value="终端上线临时-通过id查询", notes="终端上线临时-通过id查询")
	 @RequestMapping(value = "/queryIotById", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<List<IotTerminalTemp>> queryIotById(@RequestBody IotTerminalTemp iotTerminalTemp) {
		 LambdaQueryWrapper<IotTerminalTemp> iotTerminalTempLambdaQueryWrapper   = new LambdaQueryWrapper<>();
		 iotTerminalTempLambdaQueryWrapper.eq(IotTerminalTemp::getSn,iotTerminalTemp.getSn());
		 List<IotTerminalTemp> iotTerminalTemps=iotTerminalTempMapper.selectList(iotTerminalTempLambdaQueryWrapper);
		 return Result.OK(iotTerminalTemps);
	 }



	 @AutoLog(value = "中控设备-添加")
	 @ApiOperation(value="中控设备-添加", notes="中控设备-添加")
	 @PostMapping(value = "/addIot")
	 public Result<String> addIot(@RequestBody IotTerminalTemp iotTerminalTemp) {
		 iotTerminalTempService.save(iotTerminalTemp);
		 return Result.OK("添加成功！");
	 }
    /**
    * 导出excel
    *
    * @param request
    * @param iotTerminalTemp
    */
    //@RequiresPermissions("org.jeecg.modules.demo:iot_terminal_temp:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, IotTerminalTemp iotTerminalTemp) {
        return super.exportXls(request, iotTerminalTemp, IotTerminalTemp.class, "终端上线临时");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("iot_terminal_temp:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, IotTerminalTemp.class);
    }

}
